package com.leoblog.util;

import org.apache.commons.lang.StringUtils;


public class UrlUtil {
	
	/**
	 * Get the relative url.
	 * @param contextPath context path.
	 * @param wholeURL whole url.
	 * @return relative url.
	 */
	public static String getRelativeURL(String contextPath, String wholeURL)
	{		
		if (StringUtils.isEmpty(contextPath))
		{
			wholeURL = wholeURL.replaceAll("http://", "");
			return wholeURL.substring(wholeURL.indexOf("/"));
		}		
		
		int contextIndex = wholeURL.indexOf(contextPath);
		
		if (contextIndex == -1)
		{
			return wholeURL;
		}
		else
		{
			return wholeURL.substring(contextIndex + contextPath.length());
		}
	}
}
